package com.szzg10.thinking.chapter18;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.LongBuffer;

public class ViewBuffers {

	public static void main(String[] args) {
		ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[] {0, 0, 0, 0, 0, 0, 0, 'a'});
		
		//byte
		byteBuffer.rewind();
		System.out.print("ByteBuffer: ");
		while(byteBuffer.hasRemaining()) {
			System.out.print(byteBuffer.get() + ", ");
		}
		System.out.println();
		
		//char
		byteBuffer.rewind();
		System.out.print("CharBuffer:");
		CharBuffer charBuffer = byteBuffer.asCharBuffer();
		while(charBuffer.hasRemaining()) {
			System.out.print(charBuffer.get() + ", ");
		}
		System.out.println();
		
		//float
		byteBuffer.rewind();
		FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
		while(floatBuffer.hasRemaining()) {
			System.out.print(floatBuffer.get() + ", ");
		}
		System.out.println();
		
		//int
		byteBuffer.rewind();
		IntBuffer intBuffer = byteBuffer.asIntBuffer();
		while(intBuffer.hasRemaining()) {
			System.out.print(intBuffer.get() + ", ");
		}
		System.out.println();
		
		//long
		byteBuffer.rewind();
		LongBuffer longBuffer = byteBuffer.asLongBuffer();
		while(longBuffer.hasRemaining()) {
			System.out.print(longBuffer.get());
		}
		System.out.println();
		
		//double
		byteBuffer.rewind();
		DoubleBuffer doubleBuffer = byteBuffer.asDoubleBuffer();
		while(doubleBuffer.hasRemaining()) {
			System.out.print(doubleBuffer.get());
		}
		System.out.println();
	}
}
